<template>
  <!-- https://blog.csdn.net/G971005287W/article/details/117741829 -->
  <div>
    <draggable
      v-model="myArray"
      chosenClass="chosen"
      forceFallback="true"
      group="people"
      animation="100"
      @start="onStart"
      @end="onEnd"
      ghostClass="ghost"
      handle=".mover"
    >
      <transition-group>
        <div class="item" v-for="element in myArray" :key="element.id">
        <span class="mover">+</span>
          {{ element.name }}√
        </div>
      </transition-group>
    </draggable>


    <!-- 表格 -->
    <TableRowSetUp />

    <!-- 自定义拖拽 -->
    <MyDrag />
  </div>
</template>

<script>
import draggable from "vuedraggable";
import TableRowSetUp from "./TableRowSetUp"
import MyDrag from "./MyDrag"
export default {
  components: {
    draggable,
    TableRowSetUp,
    MyDrag
  },
  data() {
    return {
      drag: false,
      //定义要被拖拽对象的数组
      myArray: [
        { people: "cn", id: 1, name: "www.itxst.com" },
        { people: "cn", id: 2, name: "www.baidu.com" },
        { people: "cn", id: 3, name: "www.taobao.com" },
        { people: "us", id: 4, name: "www.google.com" },
      ],
    };
  },
  methods: {
    //开始拖拽事件
    onStart() {
      this.drag = true;
    },
    //拖拽结束事件
    onEnd() {
      this.drag = false;
    },
  },
};
</script>

<style lang="less" scoped>
.item {
  background-color: #fff;
  padding: 10px;
  margin: 10px;
  border: 1px solid #ccc;
  border-radius: 5px;
  user-select: none;
  color: #888;
}
.chosen{
    border-color: aqua;
}
.ghost{
    border-color: rgb(255, 255, 255);
}
.mover{
    display: inline-block;
    width: 20px;
    height: 20px;
    background-color: #fff;
    border: 1px solid #ccc;
    cursor: pointer;
    color:#ccc;
    font-size: 16px;
    text-align: center;
    line-height: 20px;
    border-radius: 4px;
}
.chosen .mover{
    color:aqua;
    border-color:aqua;
}
</style>